package cn.swing.learning;

import javax.swing.*;
import javax.swing.table.DefaultTableModel;
import javax.swing.table.TableModel;

/**
 * Desc : TODO
 * ClassName : cn.swing.learning.RankingListTabel
 *
 * @author : 林鹏群
 * @date : 2022/12/24 9:06
 */
public class RankingListTabel extends JTable {

    private DefaultTableModel tableModel;

    public RankingListTabel(Object[][] cellData,String[] columnNames) {
//        super(cellData,columnNames);

        this.setModel(new DefaultTableModel(
                cellData,columnNames
        ));

        tableModel = (DefaultTableModel)this.getModel();



        this.setRowHeight(30);
        this.setShowGrid(true);
    }

    public void addData(String level,String times,String name){

        tableModel.addRow(new Object[]{level, times,name});
        this.setModel(tableModel);
    }
    public void delData(){
        int[] rows = this.getSelectedRows();
        for (int i = 0; i < rows.length; i++) {
            tableModel.removeRow(rows[0]);
        }
        this.setModel(tableModel);
    }

    public void queryData() {
//        int[] rows = this.getSelectedRows();
        int row = this.getSelectedRow();
        for (int i = 0; i < 3; i++) {
            Object value = this.getValueAt(row, i);
            System.out.println(value);
        }

    }
}
